package com.gimi.cloud.jimi.commonService.common.impl;

import com.gimi.cloud.jimi.commonService.common.JmUserService;
import com.gimi.cloud.jimi.dao.dao.User.UserInfoDao;
import com.gimi.cloud.jimi.dao.dao.User.WorkInfoDao;
import com.gimi.cloud.jimi.dao.dao.bank.BankDao;
import com.gimi.cloud.jimi.dao.dao.moreInfo.MoreInfoDao;
import com.gimi.cloud.jimi.dao.dao.userInfo.EmergencyContactDao;
import com.gimi.cloud.jimi.dao.dao.userInfo.RdJxlDao;
import com.gimi.cloud.jimi.dto.app.moreInfo.MoreInfoDTO;
import com.gimi.cloud.jimi.dto.userInfo.RdEmergencyContactDTO;
import com.gimi.cloud.jimi.dto.userInfo.RdJxlDTO;
import com.gimi.cloud.jimi.dto.userInfo.RdUserInfoDTO;
import com.gimi.cloud.jimi.dto.userInfo.RdWorkInfoDTO;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by shazhiwei on 2018/1/17.
 */
@Service
public class JmUserServiceImpl implements JmUserService {
    private final WorkInfoDao workInfoDao;
    private final UserInfoDao userInfoDao;
    private final EmergencyContactDao emergencyContactDao;
    private final RdJxlDao rdJxlDao;
    private final MoreInfoDao moreInfoDao;
    private final BankDao bankDao;

    public JmUserServiceImpl(WorkInfoDao workInfoDao,UserInfoDao userInfoDao,EmergencyContactDao emergencyContactDao,
                             RdJxlDao rdJxlDao,MoreInfoDao moreInfoDao,BankDao bankDao){
     this.workInfoDao = workInfoDao;
     this.userInfoDao = userInfoDao;
     this.emergencyContactDao = emergencyContactDao;
     this.rdJxlDao = rdJxlDao;
     this.moreInfoDao = moreInfoDao;
     this.bankDao = bankDao;
    }

    @Override
    public Map<String,Object> getDataStatus(Integer userId) {
        Map<String,Object> map = new HashMap<>();

        map.put("userInfoOverDue",userInfoOverDue(userId));//身份认证是否过期
        map.put("bankInfoOverDue",bankInfoOverDue(userId));//银行卡信息否过期
        map.put("workInfoOverDue",workInfoOverDue(userId));//工作信息是否过期
        map.put("emergencyContactOverDue",emergencyContactOverDue(userId));//联系人信息是否过期
        map.put("jxlOverDue",jxlOverDue(userId));//运营商信息是否过期
        map.put("sheBaoOverDue",sheBaoOverDue(userId));//社保信息是否过期(还没建表)
        return map;
    }

    /**
     * 获取身份认证信息是否过期
     * @param userId 用户id
     * @return
     */
    boolean userInfoOverDue(Integer userId){
        boolean result = true;
        RdUserInfoDTO userInfo = userInfoDao.getEffectionByUserId(userId);
        if(userInfo != null){
            Date effection = userInfo.getReportEffectionEnd();
            if(effection != null && effection.compareTo(new Date()) > 0){
                result = false;
            }
        }
        return result;
    }

    /**
     * 获取银行卡认证信息是否过期
     * @param userId 用户id
     * @return
     */
    boolean bankInfoOverDue(Integer userId){
        boolean result = true;
        /*BankCardDTO bankCard = bankDao.getEffectionByUserId(userId);
        if(bankCard != null){
            Date effection = bankCard.getReportEffectionEnd();
            if(effection != null && effection.compareTo(new Date()) > 0){
                result = false;
            }
        }*/
        return result;
    }

    /**
     * 获取工作信息是否过期
     * @param userId 用户id
     * @return
     */
    boolean workInfoOverDue(Integer userId){
        boolean result = true;
        RdWorkInfoDTO workInfo = workInfoDao.getEffectionByUserId(userId);
        if(workInfo != null){
            Date effection = workInfo.getReportEffectionEnd();
            if(effection != null && effection.compareTo(new Date()) > 0){
                result = false;
            }
        }
        return result;
    }

    /**
     * 获取联系人信息是否过期
     * @param userId 用户id
     * @return
     */
    boolean emergencyContactOverDue(Integer userId){
        boolean result = true;
        RdEmergencyContactDTO emergencyContact = emergencyContactDao.getEffectionByUserId(userId);
        if(emergencyContact != null){
            Date effection = emergencyContact.getReportEffectionEnd();
            if(effection != null && effection.compareTo(new Date()) > 0){
                result = false;
            }
        }
        return result;
    }


    /**
     * 获取运营商认证信息是否过期
     * @param userId 用户id
     * @return
     */
    boolean jxlOverDue(Integer userId){
        boolean result = true;
        RdJxlDTO jxlDTO = rdJxlDao.getEffectionByUserId(userId);
        if(jxlDTO != null){
            Date effection = jxlDTO.getReportEffectionEnd();
            if(effection != null && effection.compareTo(new Date()) > 0){
                result = false;
            }
        }
        return result;
    }

    /**
     * 获取运营商认证信息是否过期
     * @param userId 用户id
     * @return
     */
    boolean sheBaoOverDue(Integer userId){
        boolean result = true;
        MoreInfoDTO moreDTO = moreInfoDao.getEffectionByUserId(userId);
        if(moreDTO != null){
            Date effection = moreDTO.getReportEffectionEnd();
            if(effection != null && effection.compareTo(new Date()) > 0){
                result = false;
            }
        }
        return result;
    }

}
